package com.testfileupload.uploadimg.design.single;

/**
 * 懒汉式(线程安全)
 * 实现了懒加载的模式，多线程安全，但是效率低
 */
public class SingleModel4 {
    public static void main(String[] args) {
        Single3 instence = Single3.getInstence();
        Single3 instence1 = Single3.getInstence();
        System.out.println(instence);
        System.out.println(instence1);
        System.out.println(instence.equals(instence1));
        System.out.println(instence == instence1);
    }
}

class Single3 {

    private static Single3 single;

    /**
     * 构造私有化，不能new
     */
    private Single3() {
    }

    /**
     * 提供共有静态方法
     *
     * @return
     */
    public static synchronized Single3 getInstence() {
        if (single == null) {
            single = new Single3();
        }
        return single;
    }

}
